package com.fp.m7.client.common;

import org.gwttime.time.DateTime;
import org.gwttime.time.format.DateTimeFormat;

/**
 * A bunch of static helper methods.
 * 
 * @author 7
 */
public class Utils {

    /**
     * Returns a html for a fixed-size image.
     */
    public static String fixedSizeImage(String url, int width, int height) {
        return new StringBuilder() //
                .append("<img src='").append(url) //
                .append("' width='").append(width) //
                .append("px' height='").append(height) //
                .append("px' />").toString();
    }

    /**
     * Returns a html for a jQuery timeago plugin, for displaying dates
     */
    public static String htmlForATimeAgoElement(DateTime date) {
        return new StringBuilder() //
                .append("<abbr class='timeago' title='").append(date.toString()).append("'>") //
                .append(date.toString(DateTimeFormat.shortDateTime())) //
                .append("</abbr>").toString();
    }

    /**
     * Parses the DOM, initializes the timeago elements via jQuery.
     */
    public static native void initJQueryTimeAgo() /*-{
		$wnd.jQuery("abbr.timeago").timeago();
    }-*/;
}
